package com.person.modules.person.controller;

import com.person.common.annotation.SysLog;
import com.person.common.utils.R;
import com.person.common.validator.ValidatorUtils;
import com.person.modules.person.entity.PunishmentEntity;
import com.person.modules.person.entity.TrainPlanEntity;
import com.person.modules.person.service.PunishmentService;
import com.person.modules.sys.controller.AbstractController;
import com.person.modules.sys.service.SysDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/person/punishment")
public class PunishmentController extends AbstractController {
    @Autowired
    PunishmentService punishmentService;
    @Autowired
    SysDeptService sysDeptService;
    @GetMapping("/list")
    @CrossOrigin
    @ResponseBody

    public R list(){
        List<PunishmentEntity> list=punishmentService.getListByCompanyId(getCompanyId());
        return  R.ok().put("list",list);
    }

    @RequestMapping("/info")
    @CrossOrigin
    @ResponseBody
    public R info(long id){
        PunishmentEntity punishmentEntity=punishmentService.getById(id);
        punishmentEntity.setDeptName(sysDeptService.getById(punishmentEntity.getDeptId()).getName());
        return  R.ok().put("list",punishmentEntity);
    }

    /**
     * 保存培训计划
     */
    @SysLog("保存处分记录")
    @RequestMapping("/save")
    @Transactional
/*    @RequiresPermissions("person:punishment:save")*/
    @CrossOrigin
    public R save(PunishmentEntity punishmentEntity){
        ValidatorUtils.validateEntity(punishmentEntity);
        punishmentEntity.setCompanyId(getUser().getCompanyId());
        punishmentService.save(punishmentEntity);
        return R.ok();
    }


}
